#ifndef CHOOSEFRIENDDIALOG_H
#define CHOOSEFRIENDDIALOG_H

#include <QDialog>
#include <QWidget>
#include <QIcon>
#include <QScrollArea>
#include <QScrollBar>
#include <QHBoxLayout>
#include <QCheckBox>
#include <QPushButton>
#include <QLabel>
#include <QStyleOption>
#include <QPainter>
#include <QMouseEvent>
#include <QEnterEvent>

#include "model/datacenter.h"

///
/// \brief 选择好友窗口中的一个 元素/好友项
///

class ChooseFriendDialog;

class ChooseFriendItem: public QWidget{
    Q_OBJECT
public:
    ChooseFriendItem(ChooseFriendDialog* owner, const QString& userId,
                     const QIcon& avatar, const QString &name, bool checked);

    void paintEvent(QPaintEvent* event) override;// 自定义类的样式需要重写此函数才能生效

    const QString& getUserId(){
        return m_userId;
    }
    QCheckBox* getCheckBox(){ return m_checkBox; }

private:
    void toggleCheckBox(bool checked);

private:
    QCheckBox* m_checkBox = nullptr;

    ChooseFriendDialog* m_owner = nullptr;
    QIcon m_avatar;
    QString m_userId;
    QString m_name;
};

///
/// \brief 选择好友窗口
///
class ChooseFriendDialog : public QDialog
{
    Q_OBJECT
public:
    ChooseFriendDialog(QWidget* parent = nullptr);

    void initLeftArea(QHBoxLayout* layout);

    void initRightArea(QHBoxLayout* layout);

    void addFriend(const QString& userId, const QIcon& avatar, const QString &name, bool checked);
    void addSelectFriend(const QString& uerId, const QIcon& avatar, const QString& name);
    void deleteSelectedFriend(const QString& userId);

private:
    QList<QString> generateMemberList();   // 拿到成员的userID

public slots:
    void clickOkBtn();  //  点击完成获取选中的成员

signals:
    void friendItemUnselect();

private:
    // 保存左侧待选中好友列表的 container
    QWidget* m_totalContainer = nullptr;
    // 保存右侧已选中好友列表的 container
    QWidget* m_selectedContainer = nullptr;
};

#endif // CHOOSEFRIENDDIALOG_H
